﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Utilities;
using Models.WebSite_HaiSheng;

namespace WebSite_HaiSheng.Controllers
{
    [AllowAnonymousAttribute]
    public class FrontController : Controller
    {
        #region 公司概况
        public ActionResult Company_AboutUs()
        {
            return View();
        }

        public ActionResult Company_Leaders()
        {
            return View();
        }
        public ActionResult Company_Organization()
        {
            return View();
        }
        public ActionResult Company_ChildrenCompanies(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }
        #endregion

        #region综合信息
        public ActionResult News_Hots(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }

        public ActionResult News_WorkingNews(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }

        public ActionResult News_Details(int? id)
        {
            if (id != null)
            {
                var article = CH.GetDataById<Article>(id);
                return View(article);
            }
            return RedirectToAction("News_Hots","front");
        }

        public ActionResult SearchNews(string search)
        {
            if (!string.IsNullOrEmpty(search))
            {
                var articles = CH.GetAllData<Article>(article =>
                    article.ArticleType.Contains(search)
                    || article.Content.Contains(search)
                    || article.Pubulisher.Contains(search)
                    || article.Title.Contains(search));
                return View(articles);
            }
            return View(CH.GetAllData<Article>());
        }

        
        #endregion

        #region工程业绩
        public ActionResult Project_Housing(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }

        public ActionResult Project_Details(int id)
        {
            
            return View(CH.GetDataById<Case>(id));
        }

        public ActionResult Project_Factory(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }

        public ActionResult Project_Public(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }

        public ActionResult Project_Professional(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }

        public ActionResult Project_Decoration(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }
        public ActionResult Project_Others(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }
        public ActionResult Project_Installation(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }
        public ActionResult Project_Telecom(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }
        public ActionResult Project_Waterproof(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }
        #endregion

        #region走进海盛
        public ActionResult Inside_HonersAward()
        {
            return View();
        }
        public ActionResult Inside_Qualification()
        {
            return View();
        }
        public ActionResult Inside_Managementstucture()
        {
            return View();
        }
        #endregion

        #region 企业文化
        public ActionResult Culture_Brands()
        {
            return View();
        }
        public ActionResult Culture_Employees()
        {
            return View();
        }
        public ActionResult Culture_Life()
        {
            return View();
        }
        #endregion

        #region 服务中心
        public ActionResult Service_Standard()
        {
            return View();
        }
        public ActionResult Service_ContactUs()
        {
            return View();
        }

        public ActionResult Service_Message(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }

        [HttpPost]
        public ActionResult Service_Message(Message m)
        {
            if (ModelState.IsValid)
            {
                m.ContentDate = DateTime.Now;
                m.ReplyDate = DateTime.Now;
                CH.Create<Message>(m);
                return RedirectToAction("Service_Message","Front");
            }
            ViewBag.Error = "Error";
            return View();
        }


        public ActionResult Service_Downloads(int? pageid)
        {
            if (pageid == null)
            {
                ViewBag.CurrentPage = 1;
            }
            else
            {
                ViewBag.CurrentPage = pageid;
            }
            return View();
        }

        public ActionResult Service_File_Donwload(int? id)
        {
            var data = CH.GetDataById<FileDownload>(id);
            return new DownloadResult { VirtualPath = data.FileUrl, FileDownloadName = data.FileName };
        }


        #endregion

        #region 加入我们
        public ActionResult JoinUs_Recruitment()
        {
            return View();
        }
        public ActionResult JoinUs_Details(int id)
        {
            return View(CH.GetDataById<Recruitment>(id));
        }

        public ActionResult JoinUs_Apply(int recruitmentId)
        {
            ViewBag.RecruitmentId = recruitmentId;
            var data = CH.GetDataById<Recruitment>(recruitmentId);
            if (data != null)
            {
                ViewBag.RecruitmentTitle = data.JobTitle;
                ViewBag.RecruitmentId = data.ID;
            }
            return View();
        }

        [HttpPost]
        public ActionResult JoinUs_Apply(JobApply jobApply)
        {
            if (ModelState.IsValid)
            {
                CH.Create<JobApply>(jobApply);
                return RedirectToAction("JoinUs_Recruitment", "Front");
                
            }
            ViewBag.Error = "Error";
            ViewBag.RecruitmentId = jobApply.RecruitmentID;
            ViewBag.RecruitmentTitle = CH.GetDataById<Recruitment>(jobApply.RecruitmentID).JobTitle;
            return View();
        }
        #endregion

        public ActionResult Index()
        {
            return View();
        }
    }
}
